package com.agranee.timesheet.bean;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

import com.agranee.timesheet.model.Employee;
import com.agranee.timesheet.service.LoginServiceImpl;
import com.agranee.timesheet.utility.Util;

@ManagedBean(name = "retrivePasswordBean")
@RequestScoped
public class RetrivePasswordBean {
	private String employeeId;

	private LoginServiceImpl loginService;

	public LoginServiceImpl getLoginService() {
		return loginService;
	}

	public void setLoginService(LoginServiceImpl loginService) {
		this.loginService = loginService;
	}

	public String getEmployeeId() {
		return employeeId;
	}

	public void setEmployeeId(String employeeId) {
		this.employeeId = employeeId;
	}

	public String retrivePassword() {
		Employee employee = this.getLoginService().getUserByEmployeeId(
				getEmployeeId());
		if (employee != null) {
			String to = employee.getEmployeeEmailId();
			String from = "";
			String subject = "Password reset request from Agranee Solutions Ltd.";
			String content = "";
			boolean isMailSend = Util.sendEmail(to, from, subject, content);
			if (isMailSend)
				return "success";
		}
		return "error";

	}

}
